#ifndef DATABASEWINDOW_H
#define DATABASEWINDOW_H

#include <QWidget>
#include <QSqlDatabase>
#include <QSqlTableModel>
#include "database.h"

QT_BEGIN_NAMESPACE
class QTableWidget;
class QComboBox;
class QPushButton;
class QLabel;
class QTableWidgetItem;
QT_END_NAMESPACE

namespace Ui {
class DatabaseWindow;
}

class DatabaseWindow : public QWidget
{
    Q_OBJECT

public:
    explicit DatabaseWindow(QWidget *parent = nullptr);
    ~DatabaseWindow();

signals:
    void windowClosed();

private slots:
    void onTableChanged(int index);
    void onAddClicked();
    void onEditClicked();
    void onDeleteClicked();
    void onDeviceInfoClicked();
    void onRefreshClicked();
    void onSaveClicked();
    void onCloseClicked();
    void onCellChanged(int row, int column);

protected:
    void closeEvent(QCloseEvent *event) override;

private:
    Ui::DatabaseWindow *ui;
    bool hasUnsavedChanges;
    Database* database;
    
    void initializeDatabase();
    void loadData();
    void updateStatus();
    void saveChanges();
    void refreshTable();
    Product getProductFromRow(int row);
    void setProductToRow(int row, const Product& product);
};

#endif // DATABASEWINDOW_H